package zhh.tangbao.auxiliary.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import zhh.tangbao.auxiliary.service.SystemFileService;
import zhh.tangbao.system.annotation.Authority;
import zhh.tangbao.system.annotation.Log;
import zhh.tangbao.system.constant.AuthorityModel;
import zhh.tangbao.system.result.Result;

/**
 * 2023/3/1
 * @author 粥灰灰
 * @version 1.0
 * 系统文件上传接口
 */

@RestController
@RequestMapping("/api/file")
public class SystemFileController {

    @Autowired
    private SystemFileService systemFileService;

    /**
     * 单个文件上传接口
     */
    @PostMapping("/upload")
    @Authority(authorities = "admin", authorityModel = AuthorityModel.CONTAIN)
    @Log(function = "上传文件", moduleName = "文件管理", isSaveRequestData = false)
    public Result upload(MultipartFile file) {
        if (!systemFileService.canUpload(file)) {
            return Result.fail().setMsg("上传文件不符合要求");
        }
        return Result.success().put(systemFileService.upload(file));
    }

}
